package com.coderush.admin.sys.controller;

import com.coderush.admin.core.common.PageResult;
import com.coderush.admin.core.response.Result;
import com.coderush.admin.core.utils.UserContextModel;
import com.coderush.admin.sys.model.dto.EmpSearchDto;
import com.coderush.admin.sys.model.vo.EmployeePageVo;
import com.coderush.admin.sys.service.EmployeeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * PackageName com.coderush.admin.sys.controller
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName EmployeeController
 * @Date 2025/9/2
 * @Description TODO
 */
@RestController
@RequestMapping("/sys/emp")
@RequiredArgsConstructor
public class EmployeeController {

    private final EmployeeService employeeService;

    /**
     * 分页查询员工列表
     */
    @Operation(summary = "分页查询员工列表", description = "分页查询员工列表")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @GetMapping("/findByPage")
    public Result<PageResult<EmployeePageVo>> findByPage(EmpSearchDto empSearchDto) {

        var pageResult = employeeService.findByPage(empSearchDto);

        return Result.buildSuccess(pageResult);
    }

    /**
     * 通过Token获取员工信息
     */
    @Operation(summary = "通过Token获取员工信息", description = "通过Token获取员工信息")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @RequestMapping("/getEmpInfo")
    public Result<UserContextModel> getEmpInfo() {

        UserContextModel empInfo = employeeService.getEmpInfo();

        return Result.buildSuccess(empInfo);
    }




}